﻿using System.Globalization;
using System.Threading;
using System.Windows.Threading;
using Mido.Domain;
using System.Windows;
using Mido.Utils.Logging;

namespace Mido
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App
	{
        private static readonly DomainModel _domainModel = new DomainModel();

	    public static DomainViewModel DomainViewModel
	    {
	        get { return new DomainViewModel(_domainModel); }
	    }

	    public App()
	    {
            DispatcherUnhandledException += OnUnhandledException;

			if (!string.IsNullOrEmpty(_domainModel.Settings.Localization))
				Thread.CurrentThread.CurrentUICulture = new CultureInfo(_domainModel.Settings.Localization);
	    }

        private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;
            Logger.Log(e.Exception);
        }

	    protected override void OnExit(ExitEventArgs e)
	    {
            _domainModel.Settings.Save();

	        base.OnExit(e);
	    }
	}
}
